package com.xiweicheng.test.proxy.doc.handler;

import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class DocClient {

	List<IDocHandler> docHandlers = new ArrayList<>();

	public DocClient addHandler(IDocHandler handler) {
		this.docHandlers.add(handler);
		return this;
	}

	public DocClient addHandlers(IDocHandler... handlers) {
		for (IDocHandler docHandler : handlers) {
			addHandler(docHandler);
		}
		return this;
	}

	public Document invoke(String html, String baseUrl, String basePath) {

		Document doc = Jsoup.parse(html);

		for (IDocHandler docHandler : docHandlers) {
			docHandler.handle(doc, baseUrl, basePath);
		}

		return doc;
	}
}
